package cn.zly.spring.context.support;

import cn.zly.spring.beans.factory.ConfigurableListableBeanFactory;
import cn.zly.spring.beans.factory.support.DefaultListableBeanFactory;

/**
 * @author zhanglianyong
 * @date 2025/1/22
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {


	private DefaultListableBeanFactory beanFactory;

	@Override
	protected void refreshBeanFactory() throws Exception {
		DefaultListableBeanFactory beanFactory = createBeanFactory();
		loadBeanDefinitions(beanFactory);
		this.beanFactory = beanFactory;
	}

	protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

	private DefaultListableBeanFactory createBeanFactory() {
		return new DefaultListableBeanFactory();
	}

	@Override
	public ConfigurableListableBeanFactory getBeanFactory() {
		return this.beanFactory;
	}
}
